<?php


namespace App\Models;

use Illuminate\Http\Response;

/**
 * 支付请求信息
 * Class PayRequestData
 *
 * @package App\Models
 * @property int $id
 * @property string $order_id
 * @property string|null $class
 * @property int|null $success
 * @property int|null $type
 * @property array $request
 * @property array $response
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @method static \Illuminate\Database\Eloquent\Builder|PayRequestData newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|PayRequestData newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|PayRequestData query()
 * @method static \Illuminate\Database\Eloquent\Builder|PayRequestData whereClass($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayRequestData whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayRequestData whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayRequestData whereOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayRequestData whereRequest($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayRequestData whereResponse($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayRequestData whereSuccess($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayRequestData whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayRequestData whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class PayRequestData extends BaseModel
{
    protected $guarded = [];
    protected $casts = [
        'request' => 'json',
        'response' => 'json',
    ];
    /**
     * 记录支付请求日志
     * @param $orderId int 订单id
     * @param $class string easywechat方法
     * @param $type 1.小程序支付
     * @param $request array 请求参数
     * @param $response Response 返回参数
     * @param $success int 是否成功
     * @return bool
     */
    public static function record($orderId, $class, $type, $request, $response, $success)
    {
        $data = array(
            'order_id' => (string)$orderId,
            'type' => (int)$type,
            'class' => (string)$class,
            'request' => (array)$request,
            'response' => (array)$response,
            'success' => (int)$success,
        );

        $model = new self();

        return $model->fill($data)->save();
    }
}